package com.qixin.part.controller;


import com.qixin.api.bean.PtRole;
import com.qixin.api.bean.ResultPage;
import com.qixin.api.bean.VoPage;
import com.qixin.api.service.PtRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author 吕正睿
 * @since 2018-11-13
 */
@Controller
@RequestMapping("/ptRole")
public class PtRoleController {
	@Autowired
	PtRoleService ptRoleService;

	//子页面请求
	@RequestMapping("/main.html")
	public String home(){
		return "/system/role";

	}
	@RequestMapping("/Role_add")
	public String Role_add (){
		return "/system/Role_add";
	}

	//查询所有角色  如果带分页参数 就分页  如果不带分页参数  就不分页
	@RequestMapping("/findRole")
	@ResponseBody
	public ResultPage<PtRole> findRole(VoPage voPage, PtRole ptRole){
		ResultPage<PtRole> resultPage=ptRoleService.selectMyPage(voPage,ptRole);
		return resultPage;
	}
	//新增角色  和菜单关联
	@RequestMapping("/insertRole")
	@ResponseBody
	public String insertRole( String param){
		if(ptRoleService.insertRoleAndMenu(param)){
			return  "新增成功";
		}
		return "服务器错误...请稍后再试";
	}
	//删除
	@RequestMapping("/deleteRole")
	@ResponseBody
	public String deleteRole(Long id)   {
		try {
			return ptRoleService.deleteRole(id);
		} catch (SQLException e) {
			return "删除失败";
		}
	}
}
